<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<div style="height: 30px"></div>
<div style="width: 500px;font-size: 10px">
    <form class="layui-form" action="" onsubmit="return false" id = 'editRule'>
        <input type="hidden" name="adminId" id="adminId" value="{$info.id}">
        <input type="hidden" name="adminRuleId" id="adminRuleId" value="{$info.admin_rule.rule_id}">
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                {foreach $rule as $value}
                    {if $value.scope == $info.admin_rule.get_rule.scope}
                        <input type="radio" checked name="ruleId" value="{$value.id}" title="{$value.scope_name}">
                    {else/}
                        <input type="radio" name="ruleId" value="{$value.id}" title="{$value.scope_name}">
                    {/if}
                {/foreach}
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="update">保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    //表单初始化
    layui.use('form', function(){
        var form = layui.form;
        layer = layui.layer;
    });
</script>
<script>
    $("#update").click(function(){
        var adminRuleId = $("#adminRuleId").val();
        if(adminRuleId == $("input[name=ruleId]:checked").val()){
            layer.msg('请选择需要修改的权限',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/admin/updateRule')}",
            data:$("#editRule").serialize(),
            type:"post",
            dataType:"json",
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function() {
                        //window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                    return;
                }
            }
        });
    });
</script>
</body>